//
//  UIBarButtonItem+Extension.swift
//  LSYWeibo
//
//  Created by 刘诗岩 on 16/4/11.
//  Copyright © 2016年 刘诗岩. All rights reserved.
//

import UIKit

extension UIBarButtonItem{
    
    convenience init(imageName: String? = nil, title: String? = nil, target: AnyObject, action: Selector){
        
        self.init()
        
        let btn = UIButton()

        btn.addTarget(target, action: action, forControlEvents: .TouchUpInside)

        // 如果有图片,设置图片
        if let img = imageName{
            btn.imageEdgeInsets = UIEdgeInsets(top: 0, left: -5, bottom: 0, right: 5)
            btn.setImage(UIImage(named: img), forState: .Normal)
            btn.setImage(UIImage(named: img + "_highlighted"), forState: .Highlighted)
        }

        btn.titleLabel?.font = UIFont.systemFontOfSize(14)
        btn.setTitle(title, forState: .Normal)
        btn.setTitleColor(UIColor.darkGrayColor(), forState: .Normal)
        btn.setTitleColor(UIColor.orangeColor(), forState: .Highlighted)
        btn.sizeToFit()
        
        //设置自定义视图
        customView = btn
        
    }
}
